package jmine.tec.script.persistent.services.excluir;

import jmine.tec.di.annotation.Injected;
import jmine.tec.script.persistent.domain.Script;
import jmine.tec.services.annotations.Execution;
import jmine.tec.services.annotations.Input;
import jmine.tec.services.annotations.Output;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.api.ActionsEnum;
import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.persist.dao.BeanNotFoundException;

/**
 * Serviço de exclusão de script
 * 
 * @author lundberg
 */
@ServiceImplementor(action = ActionsEnum.EXCLUIR)
public class ScriptService {

    public static final String IDENTIFICADOR = "Identificador";

    public static final String MNEMONICO = "Mnemônico";

    public static final String TEXTO = "Texto";

    // Injected
    private BaseDAO<Script> dao;

    /**
     * Inclui um novo script Hydra ao sistema.
     * 
     * @param mnemonico mnemonico
     * @param texto texto
     * @throws BeanNotFoundException caso não encotre o script com o mnemonico passado.
     */
    @Execution
    @Output(propertyName = IDENTIFICADOR)
    public void execute(@Input(fieldName = MNEMONICO) String mnemonico, @Input(fieldName = TEXTO) String texto)
            throws BeanNotFoundException {
        Script script = this.dao.findByNaturalKey(mnemonico);
        script.getPersister().remove();
    }

    /**
     * @param dao the dao to set
     */
    @Injected
    public void setDao(BaseDAO<Script> dao) {
        this.dao = dao;
    }
}
